import axios from '@/api/fetch';
//import * as types from './types';
import SERVER from '@/api/server';

//待回运旧件查询
//待回运旧件查询 - 主页面查询
export const getListByPage = params => axios.post(`${SERVER.CLAIMDEALER}/rPCmsClaim/getPreReturnListByPage`,  params);
export const getListByPageNew = params => axios.post(`${SERVER.CLAIMDEALER}/rPCmsClaim/getPreReturnListByPageNew`,  params);

//通过ID查
export const selectById = params => axios.get(`${SERVER.CLAIMDEALER}/rPCmsClaim/selectById/${params.id}`);

//导出
export const getListForExport = (params) => axios.post(`${SERVER.CLAIMDEALER}/rPCmsClaim/getListForExportShippedBack`, params, {
  responseType: 'blob'
});

//导出
// export const getListForExport = (params) => axios.post(`${SERVER.CLAIMFAC}/rPAutoRule/getListForExport`, params, {
//   responseType: 'blob'
// });
//导出2
export const getPreReturnListForExportNew = (params) => axios.post(`${SERVER.CLAIMDEALER}/rPCmsClaim/getPreReturnListForExport`, params, {
  responseType: 'blob'
});
export const getPreReturnListForExport = params =>
  axios({//用axios发送post请求
    method: 'post',
    url: `${SERVER.CLAIMDEALER}/rPCmsClaim/getPreReturnListForExport`,//请求地址
    responseType: 'blob',//表明返回服务器返回的数据类型
    headers: {'Content-Type': 'application/json'},
    data: params
  })
    .then(res => {//处理返回的文件流
      const blob = new Blob([res.data]);//newBlob([res])中不加data就会返回下图中[objeceobjece]内容（少取一层）
      if (res.headers['content-disposition']) {
        const fileName = decodeURI(res.headers['content-disposition'].split(';')[1].split('=')[1]); //这里可以自定义名称，发现设置xlsx文件类型下载后打开会提示下面图-1的无效报错,所以我用了xls格式
        const elink = document.createElement('a');
        elink.download = fileName;
        elink.style.display = 'none';
        elink.href = URL.createObjectURL(blob);
        document.body.appendChild(elink);
        elink.click();
        URL.revokeObjectURL(elink.href);//释放URL对象
        document.body.removeChild(elink);
      }
    })

// export const getListForExport = params =>
//   axios({//用axios发送post请求
//     params:params,
//     method: 'post',
//     url: `${SERVER.CLAIMFAC}/rPAutoRule/getListForExport`,//请求地址
//     responseType: 'blob',//表明返回服务器返回的数据类型
//     headers: {'Content-Type': 'application/json'}
//   })
//     .then(res => {//处理返回的文件流
//       const blob = new Blob([res.data]);//newBlob([res])中不加data就会返回下图中[objeceobjece]内容（少取一层）
//       const fileName = decodeURI(res.headers['content-disposition'].split(';')[1].split('=')[1]); //这里可以自定义名称，发现设置xlsx文件类型下载后打开会提示下面图-1的无效报错,所以我用了xls格式
//       const elink = document.createElement('a');
//       elink.download = fileName;
//       elink.style.display = 'none';
//       elink.href = URL.createObjectURL(blob);
//       document.body.appendChild(elink);
//       elink.click();
//       URL.revokeObjectURL(elink.href);//释放URL对象
//       document.body.removeChild(elink);
//     })

  //下载中心导出
  export const exporturl = params => axios.post(`/api/cmscloud.excel/downloadExcel/exportExcel/${params.CODE}`, params);

export const getReturnDetailByClaimId = params => axios.get(`${SERVER.CLAIMDEALER}/rPCmsClaim/getReturnDetailByClaimId`, { params });

export const generateLabel = params => axios.get(`${SERVER.CLAIMDEALER}/rPCmsClaim/generateLabel`, { params });
export const generateLabelList = data => axios.post(`${SERVER.CLAIMDEALER}/rPCmsClaim/generateLabelList`,   null ,{params : data});
// 打印回运清单
export const generateReturnList = params => axios.post(`${SERVER.CLAIMDEALER}/rPCmsClaim/generateReturnList`,  params);


// 打印回运箱标
export const generateCarton = params => axios.get(`${SERVER.CLAIMDEALER}/rPReturn/generateLabelList`, { params });


export const generateLabelPostList = params => axios.post(`${SERVER.CLAIMDEALER}/rPCmsClaim/generateLabelPostList`,  params);
